package com.briup.dataset.service.impl;

import com.briup.dataset.entity.Entity;
import com.briup.dataset.mapper.EntityMapper;
import com.briup.dataset.service.IEntityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 实体（图片）服务实现类
 */
@Service
public class EntityServiceImpl implements IEntityService {
    @Autowired
    private EntityMapper entityMapper;
    /*
     * @Description 批量删除图片
     * @Date 2021/6/4 9:42
     * @Param [id] 图片id
     **/
    @Transactional
    @Override
    public void deleteEntityById(List<Integer> ids) {
        ids.forEach(id->{
            entityMapper.deleteByPrimaryKey(id); // 也可使用<foreach>标签
        });
    }
    /*
     * @Description 将指定图片移动到新分类下
     * @Date 2021/6/4 9:48
     * @Param [parseInt, parseInt1]
     * @return void
     **/
    @Transactional
    @Override
    public void removeImage(int classifyId, List<Integer> entityIds) {
       entityIds.forEach(entityId->{
           Entity entity = new Entity();
           entity.setId(entityId);
           entity.setClassifyId(classifyId);
           entityMapper.updateByPrimaryKeySelective(entity);
       });
    }


//    @Transactional
//    @Override
//    public void insertEntity2(Integer classify_id, List<byte[]> entityStringList) {
//        for (byte[] entryByte : entityStringList) {
//            // 随机生成uuid
//            String uuid = UUID.randomUUID().toString();
//            // 在hdfs中保存图片的uuid(此时需要将64字符串编码换成图片字节数组)
//            String pitcureKey = QiniuUtil.upload2Qiniu(entryByte, uuid);
//            // 将uuid以及clalssify插入到数据库
//            Entity entity = new Entity();
//            entity.setClassifyId(classify_id);
//            entity.setEntityUuid(pitcureKey);
//            entityMapper.insert(entity);
//        }
//    }
}
